package cn.zjweu.controller;

import cn.zjweu.pojo.User;
import cn.zjweu.service.RegisterService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "register简单测试接口")
@Service
@CrossOrigin
@RequestMapping("/api/v1/register")
public class RegisterController {

    @Autowired
    private RegisterService registerService;

    @ResponseBody
    @PostMapping("/register")
    public Object registerService(@RequestBody Map<String, String> data) {
        String username = data.get("username");
        String password = data.get("password");
        String trueName = data.get("trueName");
        String telephone = data.get("telephone");
        String city = data.get("city");
        String address = data.get("address");

        User user = registerService.isExist(username);
        HashMap<String, Object> map = new HashMap<>();
        if (user == null) {
            int status = registerService.register(username, password, trueName, telephone, city, address);
            map.put("isOk", status > 0);

        }else {
            map.put("isOk", false);
        }
        return map;
    }
}
